﻿/*
 * Malte Frerichs
 * Melvin Bos
 * Jasper ter Weeme
 */

using System;
using System.Collections.Generic;

namespace SortOf
{
    public class ShellSort : ISort
    {
        public void Apply<T>(IList<T> list) where T : IComparable<T>
        {
            int count = list.Count;

            // gap op de helft
            int gap = count / 2;

            while (gap > 0)
            {
                for (int i = gap; i < count; i++)
                {
                    T value = list[i];
                    int j = i;

                    while (j >= gap && list[j - gap].CompareTo(value) > 0)
                    {
                        list[j] = list[j - gap];
                        j -= gap;
                    }

                    list[j] = value;
                }

                gap = gap / 2;
            }
        }
    }
}
